package com.wang.myblog.service.impl;

import com.wang.myblog.controller.common.UploadController;
import com.wang.myblog.entity.Front;
import com.wang.myblog.mapper.FrontMapper;
import com.wang.myblog.service.FrontService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FrontServiceImpl implements FrontService {


    @Autowired
    private FrontMapper frontMapper;

    @Override
    public Front queryById(Integer id) {
        return frontMapper.queryById(1);
    }

    @Override
    public boolean update(Front front) {
        Front front1=frontMapper.queryById(1);
        if(frontMapper.update(front)==1){
            if (!front.getBackground().equals(front1.getBackground())){
                UploadController.deleteCommonImg(front1.getBackground());
            }
            if(!front.getNoticeImg().equals(front1.getNoticeImg())){
                UploadController.deleteCommonImg(front1.getNoticeImg());
            }
            return true;
        }else {
            return false;
        }
    }
}
